<?php
namespace app\common\trail;

/**
 * DAO基础操作
 */
trait DaoTrail
{
    /**
     * 获取数据结构
     * 
     * @return array
     */
    public function trailGetSchema()
    {
        $schema = (new $this->model)->myTableSchema;

        // 截取需要的字段
        $variable = ["：", ":", "，", ",", "（", "("];
        foreach ($schema as $key => $value) {
            $comment = $value["comment"];

            // 默认
            if (empty($comment)) {
                if ($key == "id") {
                    $comment = "ID";
                } else if ($key == "create_time") {
                    $comment = "创建时间";
                } else if ($key == "update_time") {
                    $comment = "修改时间";
                } else {
                    $comment = ucfirst($key);
                }
            }

            // 截取
            foreach ($variable as $v) {
                if (strpos($comment, $v) !== false) {
                    $comment = trim(substr($comment, 0, strpos($comment, $v)));
                    continue;
                }
            }

            $schema[$key]["comment"] = $comment;
        }

        return $schema;
    }
}
